// index.js
Page({
  data: {
    pageIndex: 1,
    pageSize: 20,
    bannerList: [],
    goodsList: []
  },
  onLoad(){
    this.getBannerList();
    this.getGoodsList();
  },

  toGoodsDetailPage( item ){
    let id = item.currentTarget.dataset.id;
    console.log("id: ", id)
    wx.navigateTo({
      url: `/pages/goods-detail/goods-detail?id=${id}`,
    })
  },

  getGoodsList(){
    wx.request({
      url: 'http://localhost:8082/app/omsGoodsInfo/pagination',
      method: "GET",
      data:{
        pageIndex: 1,
        pageSize: 20
      },
      success: (res) => {
        res = res.data;
        if( res.code != 200 ){
          return;
        }
        let data = res.data;
        let list =  data.list;
        list = list.map( item=>{
        let actualPrice = item.actualPrice+"";
          return {
            ...item,
            actualIntPrice:actualPrice.substring(0, actualPrice.length-2),
            actualFloatPrice: actualPrice.substring(actualPrice.length-2)
          }
        } )
        console.log(list)
        this.setData({
          goodsList: list,
          pageIndex: data.pageIndex,
          pageSize: data.pageSize
        })
      },
      fail: (err)=>{
        console.error("2222", err)
      }
    })
  },

  getBannerList(){
    wx.request({
      url: 'http://localhost:8082/app/smsBanner/pagination',
      method: "GET",
      data:{
        pageIndex: 1,
        pageSize: 20
      },
      success: (res) => {
        res = res.data;
        if( res.code != 200 ){
          return;
        }
        let data = res.data;
        let list =  data.list;
        console.log(list)
        this.setData({
          bannerList: list
        })
      },
      fail: (err)=>{
        console.error("2222", err)
      }
    })
  }
})
